import VueRouter from "vue-router"
import vue from 'vue'
vue.use(VueRouter)
//引入组件
//VueRouter路由器
const routes = new VueRouter({
    mode: 'history',
    //routes 路由
    routes: [{
        path: '/',
        component: () =>
            import('../App.vue'),
            redirect: { name: 'login' },

    }, {
        //路由跳转的路径，自己命名
        path: '/login',
        name: 'login',
        component: () =>
            import('../components/login.vue'),

        beforeEnter: (to, from, next) => {
            if (Number(localStorage.getItem('islogin'))) {
                next({ name: 'home' })
            } else {
                next()
            }
        }
    },
    // element页面
    {
        path: '/element',
        name: 'element',
        component: () =>
            import('../components/element.vue'),
        redirect: { name: 'home' },
        children: [
            //首页
            {
                path: '/home',
                component: () =>
                    import('../components/home.vue'),
                name: 'home',
            },
            //商品页面  
            {
                path: '/shop',
                component: () =>
                    import('../components/shop.vue'),
                name: 'shop',
            },
            //用户管理
            {
                path: '/user',
                component: () =>
                    import('../components/user.vue'),
                name: 'user',
            },
            //其他
            {
                path: "/other",
                component: () =>
                    import('../components/other.vue'),
                name: "other"
            }

        ],
        beforeEnter: (to, from, next) => {
            if (Number(localStorage.getItem('islogin'))) {
                next()
            } else {
                next({ name: 'login' })
            }

        }
    },


    ]
});
export default routes;